﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Prompt.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace SLS.ExClassLib.WFActivities
{
    using System.Activities;
    using System.ComponentModel;
    using SLS.ExClassLib.Message;
    using SLS.ExClassLib.MVVM;
    /// <summary>
    /// The display prompt.
    /// </summary>
    public sealed class Buffer : CodeActivity
    {
        #region Properties

        /// <summary>
        ///   Gets or sets Line.
        /// </summary>
        [DefaultValue(null)]
        public InArgument<string> InOrOutput { get; set; }

        /// <summary>
        ///   Gets or sets Text.
        /// </summary>
        [DefaultValue(null)]
        public InArgument<MessageEx> msg { get; set; }

        /// <summary>
        /// Gets or sets Transition.
        /// </summary>
        /// <remarks>
        /// Some prompts also enable a transition.  If the prompt
        /// does not enable a transition the value will be MachineTransition.None
        /// </remarks>
        public MachineTransition Transition { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// The cache metadata.
        /// </summary>
        /// <param name="metadata">
        /// The metadata.
        /// </param>
        protected override void CacheMetadata(CodeActivityMetadata metadata)
        {
            metadata.RequireExtension(typeof(IDataModel));
            metadata.AddArgument(new RuntimeArgument("msg", typeof(MessageEx), ArgumentDirection.In, false));
            metadata.AddArgument(new RuntimeArgument("InOrOutput", typeof(string), ArgumentDirection.In, false));
        }

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            var wfmViewModel = context.GetExtension<IDataModel>();
 
            if (InOrOutput.Get(context) == "IN")
            {
                wfmViewModel.InputJobPool(msg.Get(context));
            }
            if (InOrOutput.Get(context) == "OUT")
            {
                wfmViewModel.InputJobPool(msg.Get(context));
            }
        } 
        #endregion
    }
}